
//
//  HMBaseTool.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/16.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMBaseTool.h"
#import "HMHttpTool.h"
#import "MJExtension.h"

@implementation HMBaseTool

+ (void)getWithUrl:(NSString *)url params:(id)params resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure{
   //参数:现在参数都是以模型的方式传进来的,所以需要 模型->字典
    NSDictionary *param = [params keyValues];
    [HMHttpTool get:url params:param success:^(id responseObj) {
        //成功
        if (success) {
            //返回的结果是字典,所以需要 字典->模型
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        //失败
        if (failure) {
            failure(error);
        }
    }];

}

+ (void)postWithUrl:(NSString *)url params:(id)params resultClass:(Class)resultClass success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    //参数:现在参数都是以模型的方式传进来的,所以需要 模型->字典
    NSDictionary *param = [params keyValues];
    [HMHttpTool post:url params:param success:^(id responseObj) {
        //成功
        if (success) {
            //返回的结果是字典,所以需要 字典->模型
            id result = [resultClass objectWithKeyValues:responseObj];
            success(result);
        }
    } failure:^(NSError *error) {
        //失败
        if (failure) {
            failure(error);
        }
    }];

}


@end
